//
//  LoginRequestProvider.m
//  SulitLoan
//
//  Created by 虞嘉伟 on 2025/2/26.
//  
  

#import "LogoutRequestProvider.h"
#import "LogoutRequest.h"


@implementation LogoutRequestProvider

+ (void)requestLogoutWithSuccess:(void(^)(BOOL success))success failure:(void(^)(YTKRequest *request))failure {
    LogoutRequest *request = [LogoutRequest new];
    [request startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        NSDictionary *dict = request.responseObject;
        if (![dict isKindOfClass:NSDictionary.class]) {
            !failure ?: failure(request);
            return;
        }
        if ([dict[@"weeps"] intValue] == 0) {
            // [NSUserDefaults.standardUserDefaults removeObjectForKey:@"token"];
            
//            User *user = User.user;
//            user.token = nil;
//            user.phone = nil;
//            [user synchronize];
            Class User = NSClassFromString(@"User");
            NSObject *user = [User performSelector:@selector(user)];
            [user performSelector:@selector(setPhone:) withObject:nil];
            [user performSelector:@selector(setToken:) withObject:nil];
            [user performSelector:@selector(synchronize)];
            
            !success ?: success(YES);
        } else {
            !failure ?: failure(request);
        }
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        !failure ?: failure(request);
    }];
}
@end
